At 15:31 +0300 on 29/04/1999, Thomas Good wrote:
>
> 0) use awk to create tabs where whitespace exists as a field separator.
> 1) use perl to tr tabs back to whitespace within double quoted strings.
> 2) use sed to change "" to \N (PROGRESS nulls are idiosyncratic/idiotic)
> 3) use sed to change ? (the PROGRESS unknown value) to \N
> 4) use sed to strip the remaining single quotes
Why not do them all in perl? Why run through 4 separate steps if you are
already going through perl?
And did you mean remaining single quotes (') or remaining double quotes (")?
You can first unify steps 0 and 1. Your perl program splits by
double-quotes, and processes every second element (which indicates it's
inside the quotes). You should use the same principle, but process only the
even-numbered strings, changing spaces to tabs, not the other way around.
> foreach $elem (@ln) {
> if ( $i % 2) {
> print '"';
> $elem =~ tr/\t/ /;
> print $elem;
> print '"';
> } else {
> print $elem;
> }
> $i++;
Instead:
foreach $elem (@ln) {
if ( $i % 2) {
print '"'.$elem.'"';
} else {
$elem =~ tr/ /\t/;
print $elem;
}
$i++;
(May need modifications, especially in the initialization part, but you get
the idea).
Adding the other modifications (assuming you meant remaining double
quotes), you get something along the lines of:
foreach $elem (@ln) {
if ( $i % 2) {
if ( $elem eq "" ) {
print "\\N";
} else {
print $elem;
}
} else {
$elem =~ tr/ /\t/;
$elem =~ s/?/\\N/;
print $elem;
}
$i++;
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma